package com.yanqu.road.server.cross3server.cmd.xrank;

import com.yanqu.road.logic.pb.XRankPb;
import com.yanqu.road.pb.cross3.activity.XRankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.cross3server.manager.Cross3XRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Cross3Protocol;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Cmd(code = Cross3Protocol.C3_XRANK_SYNC_CHANNEL_RANK_PART_FROM_CHANNEL, desc = "跨区域服 同步区域榜 个人贡献")
public class XRankSyncChannelRankFromChannelCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XRankProto.XChannelRankPartListMsg reqMsg = XRankProto.XChannelRankPartListMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        int conditionType = reqMsg.getConditionType();
        List<XRankProto.XChannelRankPartMsg> partMsgList = reqMsg.getPartMsgList();

        Set<Integer> channelIdSet = new HashSet<>();
        for (XRankProto.XChannelRankPartMsg partMsg : partMsgList) {
            Cross3XRankMgr.getChannelRankMap().partValueChange(
                    XRankPb.parseXChannelRankPart(activityId, conditionType, partMsg), false, false
            );
            channelIdSet.add(partMsg.getChannelId());
        }
        for (int channelId : channelIdSet) {
            Cross3XRankMgr.getChannelRankMap().rankChange(activityId, conditionType, channelId);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
